package com.army.study.database;

import ohos.data.orm.OrmContext;
import ohos.data.orm.OrmPredicates;

import java.util.List;

/**
 * 卡片数据库操作
 */
public class DBUtils {

    /**
     * 保存卡片
     * @param form
     * @param connect
     */
    public static void insert(Form form, OrmContext connect) {
        connect.insert(form);
        connect.flush();
    }

    /**
     * 删除卡片
     * @param formId
     * @param connect
     */
    public static void delete(long formId, OrmContext connect) {
        OrmPredicates where = connect.where(Form.class);
        where.equalTo("formId", formId);
        List<Form> query = connect.query(where);
        if (!query.isEmpty()) {
            connect.delete(query.get(0));
            connect.flush();
        }
    }
}
